<?php

if (!defined('BASEPATH'))
    exit('Tidak Diperkenankan mengakses langsung');
/* Class  Model : contacus
 * di Buat oleh Diar PHP Generator
 * Update List untuk grid karena program generatorku lom sempurna ya hehehehehe */

class modelcontacus extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function getArrayListcontacus() { /* spertinya perlu lock table */
        $xBuffResul = array();
        $xStr = "SELECT " .
                "idx," .
                "Nama," .
                "alamat," .
                "notelpon," .
                "email," .
                "isi," .
                "tglisi" .
                " FROM contacus   order by idx ASC ";
        $query = $this->db->query($xStr);
        foreach ($query->result() as $row) {
            $xBuffResul[$row->idx] = $row->Nama;
        }
        return $xBuffResul;
    }

    function getListcontacus($xAwal, $xLimit, $xSearch='') {
        if (!empty($xSearch)) {
            $xSearch = "Where Nama like '%" . $xSearch . "%'";
        }
        $xStr = "SELECT " .
                "idx," .
                "Nama," .
                "alamat," .
                "notelpon," .
                "email," .
                "isi," .
                "tglisi" .
                " FROM contacus $xSearch order by idx DESC limit " . $xAwal . "," . $xLimit;
        $query = $this->db->query($xStr);
        return $query;
    }

    function getDetailcontacus($xidx) {
        $xStr = "SELECT " .
                "idx," .
                "Nama," .
                "alamat," .
                "notelpon," .
                "email," .
                "isi," .
                "tglisi" .
                " FROM contacus  WHERE idx = '" . $xidx . "'";

        $query = $this->db->query($xStr);
        $row = $query->row();
        return $row;
    }

    function getLastIndexcontacus() { /* spertinya perlu lock table */
        $xStr = "SELECT " .
                "idx," .
                "Nama," .
                "alamat," .
                "notelpon," .
                "email," .
                "isi," .
                "tglisi" .
                " FROM contacus order by idx DESC limit 1 ";
        $query = $this->db->query($xStr);
        $row = $query->row();
        return $row;
    }

    Function setInsertcontacus($xidx, $xNama, $xalamat, $xnotelpon, $xemail, $xisi, $xtglisi) {
        $xStr = " INSERT INTO contacus( " .
                "idx," .
                "Nama," .
                "alamat," .
                "notelpon," .
                "email," .
                "isi," .
                "tglisi) VALUES('" . $xidx . "','" . $xNama . "','" . $xalamat . "','" . $xnotelpon . "','" . $xemail . "','" . $xisi . "',current_date)";
        $query = $this->db->query($xStr);
        return $xidx;
    }

    Function setUpdatecontacus($xidx, $xNama, $xalamat, $xnotelpon, $xemail, $xisi, $xtglisi) {
        $xStr = " UPDATE contacus SET " .
                "idx='" . $xidx . "'," .
                "Nama='" . $xNama . "'," .
                "alamat='" . $xalamat . "'," .
                "notelpon='" . $xnotelpon . "'," .
                "email='" . $xemail . "'," .
                "isi='" . $xisi . "'," .
                "tglisi='" . $xtglisi . "' WHERE idx = '" . $xidx . "'";
        $query = $this->db->query($xStr);
        return $xidx;
    }

    function setDeletecontacus($xidx) {
        $xStr = " DELETE FROM contacus WHERE contacus.idx = '" . $xidx . "'";

        $query = $this->db->query($xStr);
    }

}

?>